##Replication code for:
##“Vodka or Bourbon? Foreign Policy Preferences Toward Russia and the US in Georgia”

##Load libraries
library(foreign)
library(prob)
library(lmtest)
library(car)
library(e1071)
library(Zelig)
library(ZeligChoice)
library(sandwich)
library(fields)
library(MASS)
library(qcc)
library(pscl)
library(effects)
library(ggplot2)
library(tseries)
library(betareg)
library(mvnormtest)
library(ltm)
library(nnet)
library(splines)
library(lme4)
library(usdm)
library(lmtest)
library(arm)
library(Hmisc)
library(foreign)
library(Zelig) #v.3.5
library(nnet)
library(effects)
library(ggplot2)
library(reshape2)

##Import data
data=read.csv (file="GeorgiaEU2011.csv")
attach(data)

##Set IV's as factor variables
CURRUNG2=as.factor (CURRUNG2)
is.factor(CURRUNG2)
RELSERV2=as.factor (RELSERV2)
is.factor(RELSERV2)
GOVTROL2=as.factor (GOVTROL2)
is.factor(GOVTROL2)
detach(data)

#####TABLE 1#####
##Model 1 of Political Ties With Russia (1 if "yes", 0 if "no") as a function of Age (years), Education (benchmarks, divided into 5 categories), whether the respondent knows Russian, but no other language (1 if "yes", 0 otherwise), if the respondent has traveled to Russia (1 if "yes", 0 otherwise), Whether the respondent is a member of the Orthodox Church (1 if "yes", 0 otherwise), whether the respondent is ethnically Georgian (1 if "yes", 0 otherwise), whether the respondent lives in an urban setting (1 if "yes", 0 otherwise), and whether the respodent trusts President, at the time of the survey, Saakashivilli

m.1=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2, data=data, family=binomial(link="logit"))
summary(m.1)

##Model 2 is the same as Model One, only adding religious service attendance (o to 4 scale, 0 is never  is more than once a week)
m.2=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2, data=data, family=binomial(link="logit"))
summary(m.2)

##Model 3 is the same as Model One, only adding attitudes of the role of government (1 to 4 scale, 1 is very much agree Gov is employee, 2 is agree gov is employee, 3 is agree gov is parent, and 4 is very much agree gov is parent)
m.3=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.3)

##Model 4 is the same Model One, only adding economic satisfaction: 1 to 4
m.4=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.4)

##Model 5 is same as Model One, only adding Role of Government and Economic Rung
m.5=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.5)

##Model 6 is the same as Model One, only adding Religious Service and Economic Rung
m.6=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.6)

##Model 7 is the same as Model One, only adding Religious Service and Role of Government
m.7=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.7)

##Model 8 is the same as Model One, only adding all three of our hypothesized variables
m.8=glm(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.8)

#####TABLE 2#####
##Model 9 is Economic Ties With Russia (1 if "yes", 0 if "no") as a function of Age (years), Education (benchmarks, divided into 5 categories), whether the respondent knows Russian, but no other language (1 if "yes", 0 otherwise), if the respondent has traveled to Russia (1 if "yes", 0 otherwise), Whether the respondent is a member of the Orthodox Church (1 if "yes", 0 otherwise), whether the respondent is ethnically Georgian (1 if "yes", 0 otherwise), whether the respondent lives in an urban setting (1 if "yes", 0 otherwise), and whether the respodent trusts President, at the time of the survey, Saakashivilli 
m.9=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2, data=data, family=binomial(link="logit"))
summary(m.9)

##Model 10 is the same as Model Nine, only adding religious service attendance (o to 4 scale, 0 is never  is more than once a week)
m.10=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2, data=data, family=binomial(link="logit"))
summary(m.10)

##Model 11 is the same as Model Nine, only adding attitudes of the role of government (1 to 4 scale, 1 is very much agree Gov is employee, 2 is agree gov is employee, 3 is agree gov is parent, and 4 is very much agree gov is parent)
m.11=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.11)

##Model 12 is the same Model Nine, only adding economic satisfaction: 1 to 4 scale
m.12=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.12)

##Model 13 is same as Model Nine, only adding Role of Government and Economic Rung
m.13=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.13)

##Model 14 is the same as Model Nine, only adding Religious Service and Economic Rung
m.14=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.14)

##Model 15 is the same as Model Nine, only adding Religious Service and Role of Government
m.15=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.15)

##Model 16 is the same as Model Nine, only adding all three of our hypothesized variables
m.16=glm(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.16)

#####TABLE 3#####
##Model 17 of Political Ties With America (1 if "yes", 0 if "no") as a function of Age (years), Education (benchmarks, divided into 5 categories), whether the respondent knows English, but no other language (1 if "yes", 0 otherwise), if the respondent has traveled to America (1 if "yes", 0 otherwise), Whether the respondent is a member of the Orthodox Church (1 if "yes", 0 otherwise), whether the respondent is ethnically Georgian (1 if "yes", 0 otherwise), whether the respondent lives in an urban setting (1 if "yes", 0 otherwise), and whether the respodent trusts President, at the time of the survey, Saakashivilli

m.17=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2, data=data, family=binomial(link="logit"))
summary(m.17)

##Model 18 is the same as Model 17, only adding religious service attendance (o to 4 scale, 0 is never  is more than once a week)
m.18=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2, data=data, family=binomial(link="logit"))
summary(m.18)

##Model 19 is the same as Model 17, only adding attitudes of the role of government (1 to 4 scale, 1 is very much agree Gov is employee, 2 is agree gov is employee, 3 is agree gov is parent, and 4 is very much agree gov is parent)
m.19=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.19)

##Model 20 is the same Model 17, only adding satisfaction with economic status, 1 to 4 scale
m.20=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.20)

##Model 21 is same as Model 17, only adding Role of Government and Economic Rung
m.21=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.21)

##Model 22 is the same as Model 17, only adding Religious Service and Economic Rung
m.22=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.22)

##Model 23 is the same as Model 17, only adding Religious Service and Role of Government
m.23=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.23)
##Model 24 is the same as Model 17, only adding all three of our hypothesized variables
m.24=glm(POLUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.24)

#####TABLE 4#####
##Model 25: Economic Ties With America (1 if "yes", 0 if "no") as a function of Age (years), Education (benchmarks, divided into 5 categories), whether the respondent knows English, but no other language (1 if "yes", 0 otherwise), if the respondent has traveled to America (1 if "yes", 0 otherwise), Whether the respondent is a member of the Orthodox Church (1 if "yes", 0 otherwise), whether the respondent is ethnically Georgian (1 if "yes", 0 otherwise), whether the respondent lives in an urban setting (1 if "yes", 0 otherwise), and whether the respodent trusts President, at the time of the survey, Saakashivilli

m.25=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2, data=data, family=binomial(link="logit"))
summary(m.25)
##Model 26 is the same as Model 25, only adding religious service attendance (o to 4 scale, 0 is never  is more than once a week)

m.26=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2, data=data, family=binomial(link="logit"))
summary(m.26)

##Model 27 is the same as Model 25, only adding attitudes of the role of government (1 to 4 scale, 1 is very much agree Gov is employee, 2 is agree gov is employee, 3 is agree gov is parent, and 4 is very much agree gov is parent)

m.27=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.27)

##Model 28 is the same Model 25, only adding economic satisfaction: 1 to 4 scale

m.28=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.28)

##Model 29 is same as Model 25, only adding Role of Government and Economic Rung
m.29=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.29)

##Model 30 is the same as Model 25, only adding Religious Service and Economic Rung
m.30=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.30)

##Model 31 is the same as Model 25, only adding Religious Service and Role of Government
m.31=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2, data=data, family=binomial(link="logit"))
summary(m.31)

##Model 32 is the same as Model 25, only adding all three of our hypothesized variables
m.32=glm(ECONUS~RESPAGE+EDUDGR2+EngOnly+TRAVELUS2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, family=binomial(link="logit"))
summary(m.32)
#


#Collection of Model Summaries for Table Creation 
#(Tables 1-4)

#####TABLE 1#####
##Table 1, Model 1
summary (m.1)
##Table 1, Model 2
summary (m.2)
##Table 1, Model 3
summary (m.3)
##Table 1, Model 4
summary (m.4)
##Table 1, Model 5
summary (m.5)
##Table 1, Model 6
summary (m.6)
##Table 1, Model 7
summary (m.7)
##Table 1, Model 8
summary (m.8)

#####TABLE 2#####
##Table 2, Model 1
summary (m.9)
##Table 2, Model 2
summary (m.10)
##Table 2, Model 3
summary (m.11)
##Table 2, Model 4
summary (m.12)
##Table 2, Model 5
summary (m.13)
##Table 2, Model 6
summary (m.14)
##Table 2, Model 7
summary (m.15)
##Table 2, Model 8
summary (m.16)

#####TABLE 3#####
##Table 3, Model 1
summary (m.17)
##Table 3, Model 2
summary (m.18)
##Table 3, Model 3
summary (m.19)
##Table 3, Model 4
summary (m.20)
##Table 3, Model 5
summary (m.21)
##Table 3, Model 6
summary (m.22)
##Table 3, Model 7
summary (m.23)
##Table 3, Model 8
summary (m.24)

#####TABLE 4#####
##Table 4, Model 1
summary (m.25)
##Table 4, Model 2
summary (m.26)
##Table 4, Model 3
summary (m.27)
##Table 4, Model 4
summary (m.28)
##Table 4, Model 5
summary (m.29)
##Table 4, Model 6
summary (m.30)
##Table 4, Model 7
summary (m.31)
##Table 4, Model 8
summary (m.32)


##BIC for Each Model
BIC(m.1)
BIC(m.2)
BIC(m.3)
BIC(m.4)
BIC(m.5)
BIC(m.6)
BIC(m.7)
BIC(m.8)
BIC(m.9)
BIC(m.10)
BIC(m.11)
BIC(m.12)
BIC(m.13)
BIC(m.14)
BIC(m.15)
BIC(m.16)
BIC(m.17)
BIC(m.18)
BIC(m.19)
BIC(m.20)
BIC(m.21)
BIC(m.22)
BIC(m.23)
BIC(m.24)
BIC(m.25)
BIC(m.26)
BIC(m.27)
BIC(m.28)
BIC(m.29)
BIC(m.30)
BIC(m.31)
BIC(m.32)

##Log Likelihood for Each Model
logLik(m.1)
logLik(m.2)
logLik(m.3)
logLik(m.4)
logLik(m.5)
logLik(m.6)
logLik(m.7)
logLik(m.8)
logLik(m.9)
logLik(m.10)
logLik(m.11)
logLik(m.12)
logLik(m.13)
logLik(m.14)
logLik(m.15)
logLik(m.16)
logLik(m.17)
logLik(m.18)
logLik(m.19)
logLik(m.20)
logLik(m.21)
logLik(m.22)
logLik(m.23)
logLik(m.24)
logLik(m.25)
logLik(m.26)
logLik(m.27)
logLik(m.28)
logLik(m.29)
logLik(m.30)
logLik(m.31)
logLik(m.32)
##

##Marginal effect plots for significant hypothesized predictors

#####FIGURE 1a-c#####Factors Influencing Support for Political Ties to Russia
# Religiosity (RELSERV2)
# Role of Government (GOVTROL2)
# Economic Satisfaction  (CURRUNG2)

m.8=zelig(POLRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, model="logit")
summary(m.8)

###religiosity

reli1<-setx(m.8, RELSERV2=0)
reli2<-setx(m.8, RELSERV2=1)
reli3<-setx(m.8, RELSERV2=2)
reli4<-setx(m.8, RELSERV2=3)
reli5<-setx(m.8, RELSERV2=4)

rel1<-sim(m.8,x=reli1)
rel2<-sim(m.8,x=reli2)
rel3<-sim(m.8,x=reli3)
rel4<-sim(m.8,x=reli4)
rel5<-sim(m.8,x=reli5)

re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)
re5<-melt(rel5$qi$ev)

r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)
r5<-data.frame(level=rep("Level 5"),re5)

com<-rbind(r1,r2,r3,r4,r5)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Level of religiosity",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4", "Level 5"))
ggsave("religiosity.pdf",width=7,height=7)
dev.off()

###Role of Government

reli1<-setx(m.8, GOVTROL2=1)
reli2<-setx(m.8, GOVTROL2=2)
reli3<-setx(m.8, GOVTROL2=3)
reli4<-setx(m.8, GOVTROL2=4)


rel1<-sim(m.8,x=reli1)
rel2<-sim(m.8,x=reli2)
rel3<-sim(m.8,x=reli3)
rel4<-sim(m.8,x=reli4)


re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)


r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)


com<-rbind(r1,r2,r3,r4)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Role of Government",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4"))
ggsave("govt.pdf",width=7,height=7)
dev.off()


###Economic Satisfaction

reli1<-setx(m.8, CURRUNG2=1)
reli2<-setx(m.8, CURRUNG2=2)
reli3<-setx(m.8, CURRUNG2=3)
reli4<-setx(m.8, CURRUNG2=4)


rel1<-sim(m.8,x=reli1)
rel2<-sim(m.8,x=reli2)
rel3<-sim(m.8,x=reli3)
rel4<-sim(m.8,x=reli4)


re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)


r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)


com<-rbind(r1,r2,r3,r4)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Economic Satisfaction",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4"))
ggsave("econsat.pdf",width=7,height=7)
dev.off()




#####FIGURE 2a-c#####Factors Influencing Support for Economic Ties to Russia

# Religiosity (RELSERV2)
# Role of Government (GOVTROL2)
# Economic Satisfaction  (CURRUNG2)

m.16<-zelig(ECONRUS~RESPAGE+EDUDGR2+RusOnly2+TRAVELRU2+Ortho+URBAN+EG2+TRUPRES2+RELSERV2+GOVTROL2+CURRUNG2, data=data, model="logit")
summary(m.16)


###religiosity

reli1<-setx(m.16, RELSERV2=0)
reli2<-setx(m.16, RELSERV2=1)
reli3<-setx(m.16, RELSERV2=2)
reli4<-setx(m.16, RELSERV2=3)
reli5<-setx(m.16, RELSERV2=4)

rel1<-sim(m.16,x=reli1)
rel2<-sim(m.16,x=reli2)
rel3<-sim(m.16,x=reli3)
rel4<-sim(m.16,x=reli4)
rel5<-sim(m.16,x=reli5)

re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)
re5<-melt(rel5$qi$ev)

r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)
r5<-data.frame(level=rep("Level 5"),re5)

com<-rbind(r1,r2,r3,r4,r5)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Level of religiosity",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4", "Level 5"))
ggsave("religiosity2.pdf",width=7,height=7)
dev.off()

###Role of Government

reli1<-setx(m.16, GOVTROL2=1)
reli2<-setx(m.16, GOVTROL2=2)
reli3<-setx(m.16, GOVTROL2=3)
reli4<-setx(m.16, GOVTROL2=4)


rel1<-sim(m.16,x=reli1)
rel2<-sim(m.16,x=reli2)
rel3<-sim(m.16,x=reli3)
rel4<-sim(m.16,x=reli4)


re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)


r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)


com<-rbind(r1,r2,r3,r4)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Role of Government",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4"))
ggsave("govt2.pdf",width=7,height=7)
dev.off()


###Economic Satisfaction

reli1<-setx(m.16, CURRUNG2=1)
reli2<-setx(m.16, CURRUNG2=2)
reli3<-setx(m.16, CURRUNG2=3)
reli4<-setx(m.16, CURRUNG2=4)


rel1<-sim(m.16,x=reli1)
rel2<-sim(m.16,x=reli2)
rel3<-sim(m.16,x=reli3)
rel4<-sim(m.16,x=reli4)


re1<-melt(rel1$qi$ev)
re2<-melt(rel2$qi$ev)
re3<-melt(rel3$qi$ev)
re4<-melt(rel4$qi$ev)


r1<-data.frame(level=rep("Level 1"),re1)
r2<-data.frame(level=rep("Level 2"),re2)
r3<-data.frame(level=rep("Level 3"),re3)
r4<-data.frame(level=rep("Level 4"),re4)


com<-rbind(r1,r2,r3,r4)

g<-ggplot(com, aes(x=level, y=value))
g+  geom_boxplot()+
  ylab("Probability of support of ties to Russia") +
  ggtitle("")+
  scale_x_discrete(name="Economic Satisfaction",
                   limits=c("Level 1","Level 2", "Level 3", "Level 4"))
ggsave("econsat2.pdf",width=7,height=7)
dev.off()


#####end of main analysis….below is code for 2007 data in Tables 4-8#########

##Analysis of 2007 Data
data=read.csv (file="CB2007Geo.csv")

##Model 33 is political ties to Russia as a function of age, education, knowing Russian, and being Georgian Orthodox)
m.33=glm(GEPOLRU2~Age2+Edu07+RusOnly07+Ortho07, data=data, family=binomial(link="logit"))
##Model 34 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, and religious service attendance)
m.34=glm(GEPOLRU2~Age2+Edu07+RusOnly07+Ortho07+Relserv07, data=data, family=binomial(link="logit"))
##Model 35 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, and current economic rung)
m.35=glm(GEPOLRU2~Age2+Edu07+RusOnly07+Ortho07+CR07, data=data, family=binomial(link="logit"))
##Model 36 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, religious service attendance and current economic rung)
m.36=glm(GEPOLRU2~Age2+Edu07+RusOnly07+Ortho07+Relserv07+CR07, data=data, family=binomial(link="logit"))
##Model 37 is political ties to Russia as a function of age, education, knowing Russian, and being Georgian Orthodox)
m.37=glm(GEECORU2~Age2+Edu07+RusOnly07+Ortho07, data=data, family=binomial(link="logit"))
##Model 38 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, and religious service attendance)
m.38=glm(GEECORU2~Age2+Edu07+RusOnly07+Ortho07+Relserv07, data=data, family=binomial(link="logit"))
##Model 39 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, and current economic rung)
m.39=glm(GEECORU2~Age2+Edu07+RusOnly07+Ortho07+CR07, data=data, family=binomial(link="logit"))
##Model 40 is political ties to Russia as a function of age, education, knowing Russian, being Georgian Orthodox, religious service attendance and current economic rung)
m.40=glm(GEECORU2~Age2+Edu07+EngOnly07+Ortho07+Relserv07+CR07, data=data, family=binomial(link="logit"))
##Model 41 is political ties to America as a function of age, education, knowing English, and being Georgian Orthodox)
m.41=glm(GEPOLUS2~Age2+Edu07+EngOnly07+Ortho07, data=data, family=binomial(link="logit"))
##Model 42 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, and religious service attendance)
m.42=glm(GEPOLUS2~Age2+Edu07+EngOnly07+Ortho07+Relserv07, data=data, family=binomial(link="logit"))
##Model 43 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, and current economic rung)
m.43=glm(GEPOLUS2~Age2+Edu07+EngOnly07+Ortho07+CR07, data=data, family=binomial(link="logit"))
##Model 44 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, religious service attendance and current economic rung)
m.44=glm(GEPOLUS2~Age2+Edu07+EngOnly07+Ortho07+Relserv07+CR07, data=data, family=binomial(link="logit"))
##Model 45 is political ties to America as a function of age, education, knowing English, and being Georgian Orthodox)
m.45=glm(GEECOUS2~Age2+Edu07+EngOnly07+Ortho07, data=data, family=binomial(link="logit"))
##Model 46 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, and religious service attendance)
m.46=glm(GEECOUS2~Age2+Edu07+EngOnly07+Ortho07+Relserv07, data=data, family=binomial(link="logit"))
##Model 47 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, and current economic rung)
m.47=glm(GEECOUS2~Age2+Edu07+EngOnly07+Ortho07+CR07, data=data, family=binomial(link="logit"))
##Model 48 is political ties to America as a function of age, education, knowing English, being Georgian Orthodox, religious service attendance and current economic rung)
m.48=glm(GEECOUS2~Age2+Edu07+EngOnly07+Ortho07+Relserv07+CR07, data=data, family=binomial(link="logit"))

summary(m.33)
summary(m.34)
summary(m.35)
summary(m.36)
summary(m.37)
summary(m.38)
summary(m.39)
summary(m.40)
summary(m.41)
summary(m.42)
summary(m.43)
summary(m.44)
summary(m.45)
summary(m.46)
summary(m.47)
summary(m.48)
BIC(m.33)
BIC(m.34)
BIC(m.35)
BIC(m.36)
BIC(m.37)
BIC(m.38)
BIC(m.39)
BIC(m.40)
BIC(m.41)
BIC(m.42)
BIC(m.43)
BIC(m.44)
BIC(m.45)
BIC(m.46)
BIC(m.47)
BIC(m.48)
logLik(m.33)
logLik(m.34)
logLik(m.35)
logLik(m.36)
logLik(m.37)
logLik(m.38)
logLik(m.39)
logLik(m.40)
logLik(m.41)
logLik(m.42)
logLik(m.43)
logLik(m.44)
logLik(m.45)
logLik(m.46)
logLik(m.47)
logLik(m.48)